package com.jp.knowledge.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.jp.knowledge.util.L;

/**
 * Created by jiayen on 17/6/14.
 */

public class CustomerViewpager  extends ViewPager {
    public CustomerViewpager(Context context) {
        this(context,null);
    }

    public CustomerViewpager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return super.onTouchEvent(ev);
    }


    /***
     * 事件拦截
     * @param ev
     * @return
     */
    private  int startX;
    private int startY;

    // 滑动距离及坐标 归还父控件焦点
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                startX= (int) ev.getX();
                startY= (int) ev.getY();

                break;
            case MotionEvent.ACTION_UP:
                break;
            case MotionEvent.ACTION_MOVE:


                int  endX = (int) ev.getX();
                int endY = (int) ev.getY();
                int diffx = Math.abs(endX-startX);
                int diffy =Math.abs(endY-startY);
                if(diffx>20&&diffy<10){//此时认为是在左右滑动
                    L.e("CustomerViewpager","左右滑动中");
                    return  true;
              }

                break;
            default:
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}
